using System;
using System.Collections.Generic;
namespace AppToolKit.Model.Validation
{
	public class ValidatorCollection
	{
		private List<IValidator> validators_;
		private Type entityType_;
		private EntityMeta entityMeta_;
		private string property_;
		public List<IValidator> Validators
		{
			get
			{
				if (this.validators_ == null)
				{
					this.validators_ = new List<IValidator>();
				}
				return this.validators_;
			}
			set
			{
				this.validators_ = value;
			}
		}
		public ValidatorCollection(Type type, EntityMeta entityMeta, string property)
		{
			this.entityType_ = type;
			this.entityMeta_ = entityMeta;
			this.property_ = property;
		}
		public ValidatorCollection(Type type, EntityMeta entityMeta, string property, List<IValidator> validators) : this(type, entityMeta, property)
		{
			this.validators_ = validators;
		}
		public ValidateResultSet Validate(object entity, object value)
		{
			ValidateResultSet validateResultSet = new ValidateResultSet();
			ValidateResultSet result;
			if (this.validators_ == null)
			{
				result = validateResultSet;
			}
			else
			{
				ValidateContext validateContext = new ValidateContext();
				validateContext.Entity = entity;
				validateContext.NewValue = value;
				validateContext.EntityType = this.entityType_;
				validateContext.Property = this.property_;
				validateContext.PropertyDescript = this.entityMeta_[this.property_].Descript;
				foreach (IValidator current in this.validators_)
				{
					ValidateResult validateResult = current.Validate(validateContext);
					if (validateResult != null)
					{
						validateResultSet.AddResult(validateResult);
						break;
					}
				}
				result = validateResultSet;
			}
			return result;
		}
		public void Merge(ValidatorCollection validators)
		{
		}
	}
}
